cd "C:\'your directory'"

use "Economy.dta"

* Graph Employment
twoway (scatter Employment year if country =="Greece", mcolor(red) msize(tiny) msymbol(square)) (connected Employment year if nuts3=="Greece", lcolor(red) mcolor(red) msize(small) msymbol(square)), xscale(range(2007 2019)) xlabel(#9, labsize(small))  xtitle("") ylabel(60(20)140, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Greece")) 
graph save "Graph" "empGreece.gph"

twoway (scatter Employment year if country =="Italy", mcolor(gold) msize(tiny)) (connected Employment year if nuts3=="Italy", lcolor(gold) mcolor(gold) msize(small) ), xscale(range(2007 2019)) xlabel(#9, labsize(small)) xtitle("")ylabel(60(20)140, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Italy")) 
graph save "Graph" "empItaly.gph"

twoway (scatter Employment year if country =="Portugal", mcolor(midblue) msize(tiny) msymbol(diamond)) (connected Employment year if nuts3=="Portugal", lcolor(midblue) mcolor(midblue) msize(small) msymbol(diamond)), xscale(range(2007 2019)) xlabel(#9, labsize(small)) xtitle("") ylabel(60(20)140, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Portugal")) 
graph save "Graph" "empPortugal.gph"

twoway (scatter Employment year if country =="Spain", mcolor(midgreen) msize(tiny) msymbol(triangle)) (connected Employment year if nuts3=="Spain", lcolor(midgreen) mcolor(midgreen) msize(small) msymbol(triangle)), xscale(range(2007 2019)) xlabel(#9, labsize(small)) xtitle("") ylabel(60(20)140, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Spain")) 
graph save "Graph" "empSpain.gph"

graph combine "empGreece.gph" "empItaly.gph" "empPortugal.gph" "empSpain.gph", graphregion(color(white)) title (Employment)
graph save "Graph" "Employment.gph", replace

* Graph GDP

twoway (scatter GDP year if country =="Greece", mcolor(red) msize(tiny) msymbol(square)) (connected GDP year if nuts3=="Greece", lcolor(red) mcolor(red) msize(small) msymbol(square)), xscale(range(2007 2019)) xlabel(#9, labsize(small))  xtitle("") ylabel(60(20)140, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Greece")) 
graph save "Graph" "gdpGreece.gph"

twoway (scatter GDP year if country =="Italy", mcolor(gold) msize(tiny)) (connected GDP year if nuts3=="Italy", lcolor(gold) mcolor(gold) msize(small) ), xscale(range(2007 2019)) xlabel(#9, labsize(small)) xtitle("")ylabel(60(20)140, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Italy")) 
graph save "Graph" "gdpItaly.gph"

twoway (scatter GDP year if country =="Portugal", mcolor(midblue) msize(tiny) msymbol(diamond)) (connected GDP year if nuts3=="Portugal", lcolor(midblue) mcolor(midblue) msize(small) msymbol(diamond)), xscale(range(2007 2019)) xlabel(#9, labsize(small)) xtitle("") ylabel(60(20)140, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Portugal")) 
graph save "Graph" "gdpPortugal.gph"

twoway (scatter GDP year if country =="Spain" & GDP<160, mcolor(midgreen) msize(tiny) msymbol(triangle)) (connected GDP year if nuts3=="Spain", lcolor(midgreen) mcolor(midgreen) msize(small) msymbol(triangle)), xscale(range(2007 2019)) xlabel(#9, labsize(small)) xtitle("")ylabel(60(20)140, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Spain")) 
graph save "Graph" "gdpSpain.gph"

graph combine "gdpGreece.gph" "gdpItaly.gph" "gdpPortugal.gph" "gdpSpain.gph", graphregion(color(white)) title (GDP)
graph save "Graph" "GDP.gph", replace

*Figure 1
graph combine "\Employment.gph" "GDP.gph", graphregion(color(white)) cols(1) ysize(14) xsize(10)
graph save "Graph" "EmpGDP.gph", replace
 

use "GIPSy2.dta"

* Graph Turnout

twoway (scatter turnout date2 if country =="Greece", mcolor(red) msize(tiny) msymbol(square)) (connected turnout date2 if nuts3=="EL", lcolor(red) mcolor(red) msize(small) msymbol(square)), xscale(range(18900 21900)) xlabel(#11, labsize(small)) xtitle("") ylabel(40(10)80, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Greece"))
graph save "Graph" "turnGreece.gph"

twoway (scatter turnout date2 if country=="Italy", mcolor(orange) msize(tiny)) (connected turnout date2 if nuts3=="IT", lcolor(orange) mcolor(orange) msize(small)), xscale(range(18900 21900)) xlabel(#11, labsize(small)) xtitle("")  ylabel(40(10)80, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Italy"))
graph save "Graph" "turnItaly.gph"

twoway (scatter turnout date2 if country=="Portugal", mcolor(midblue) msize(tiny) msymbol(diamond)) (connected turnout date2 if nuts3=="PT", lcolor(midblue) mcolor(midblue) msize(small) msymbol(diamond)), xscale(range(18900 21900)) xlabel(#11, labsize(small)) xtitle("")  ylabel(40(10)80, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Portugal"))
graph save "Graph" "turnPortugal.gph"

twoway (scatter turnout date2 if country=="Spain", mcolor(midgreen) msize(tiny) msymbol(triangle))  (connected turnout date2 if nuts3=="ES", lcolor(midgreen) mcolor(midgreen) msize(small) msymbol(triangle)), xscale(range(18900 21900)) xlabel(#11, labsize(small)) xtitle("")  ylabel(40(10)80, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Spain"))
graph save "Graph" "turnSpain.gph"

graph combine "turnGreece.gph" "turnItaly.gph" "turnPortugal.gph" "turnSpain.gph", graphregion(color(white)) title (Turnout)
graph save "Graph" "Turnout.gph", replace



twoway (scatter deltaincumbent date2 if country =="Greece", mcolor(red) msize(tiny) msymbol(square)) (connected deltaincumbent date2 if nuts3=="EL", lcolor(red) mcolor(red) msize(small) msymbol(square)), xscale(range(18900 21900)) xlabel(#11, labsize(small)) xtitle("") yline(0, lcolor(cranberry) lwidth(vthin)) ylabel(-40(20)20, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Greece"))
graph save "Graph" "deltaGreece.gph", replace

twoway (scatter deltaincumbent date2 if country=="Italy", mcolor(orange) msize(tiny)) (connected deltaincumbent date2 if nuts3=="IT", lcolor(orange) mcolor(orange) msize(small)), xscale(range(18900 21900)) xlabel(#11, labsize(small)) xtitle("")  yline(0, lcolor(cranberry) lwidth(vthin)) yscale(range(-50 20)) ylabel(-40(20)20, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Italy"))
graph save "Graph" "deltaItaly.gph", replace

twoway (scatter deltaincumbent date2 if country=="Portugal", mcolor(midblue) msize(tiny) msymbol(diamond)) (connected deltaincumbent date2 if nuts3=="PT", lcolor(midblue) mcolor(midblue) msize(small) msymbol(diamond)), xscale(range(18900 21900)) xlabel(#11, labsize(small)) xtitle("")  yline(0, lcolor(cranberry) lwidth(vthin)) ylabel(-40(20)20, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Portugal"))
graph save "Graph" "deltaPortugal.gph", replace

twoway (scatter deltaincumbent date2 if country=="Spain", mcolor(midgreen) msize(tiny) msymbol(triangle))  (connected deltaincumbent date2 if nuts3=="ES", lcolor(midgreen) mcolor(midgreen) msize(small) msymbol(triangle)), xscale(range(18900 21900)) xlabel(#11, labsize(small)) xtitle("")  yline(0, lcolor(cranberry) lwidth(vthin)) ylabel(-40(20)20, gmin gmax) ytitle("") graphregion(color(white)) bgcolor(white) legend (region(lwidth(none)) order(2 "Spain"))
graph save "Graph" "deltaSpain.gph", replace

graph combine "deltaGreece.gph" "deltaItaly.gph" "deltaPortugal.gph" "deltaSpain.gph", graphregion(color(white)) title (Change Incumbent vote)
graph save "Graph" "Deltapct.gph", replace


*Figure 2
graph combine "Turnout.gph" "Deltapct.gph", graphregion(color(white)) cols(1) ysize(14) xsize(10)
graph save "Graph" "TurnDelta.gph", replace



*Table A.2 descriptives
by CNTR_COD, sort: sum emprate growth deltaincumbent deltaturnout



*Table A.3 empty model 
mixed incumbent ||ncountry: ||_all:R.nuts3 ||_all:R.countryelection
estimates store empty
estimates stats empty


*Table 2
* Basic
mixed incumbent lagincumbent emprate growth coalition deltaturnout early magnitude enep disp i.URBN_TYPE border metropolitan||ncountry: ||_all:R.nuts3 ||_all:R.countryelection
estimates store basic

*Table 3 (Table A.4)
*Regional benchmark
mixed incumbent lagincumbent emprate empnut2 growth gronut2 coalition deltaturnout early magnitude enep disp i.URBN_TYPE border metropolitan||ncountry: ||_all:R.nuts3 ||_all:R.countryelection
estimates store bench2

* National benchmark
mixed incumbent lagincumbent emprate empnut0 growth gronut0 coalition deltaturnout early magnitude enep disp i.URBN_TYPE border metropolitan||ncountry: ||_all:R.nuts3 ||_all:R.countryelection
estimates store bench0

*Regional and National benchmark
mixed incumbent lagincumbent emprate empnut2 empnut0 growth gronut2 gronut0 coalition deltaturnout early magnitude enep disp i.URBN_TYPE border metropolitan||ncountry: ||_all:R.nuts3 ||_all:R.countryelection
estimates store bench02

* Longitudinal benchmark
mixed incumbent lagincumbent emprate empmax growth gromax coalition deltaturnout early magnitude enep disp i.URBN_TYPE border metropolitan||ncountry: ||_all:R.nuts3 ||_all:R.countryelection
estimates store benchmax

estimates stats basic bench2 bench0 bench02 benchmax



